/**
 * 定义视频管理模块
 */
(function(window, angular, undefined){
	var module = angular.module('water.apps.ws.wsclcManager.wsclcInfo.videoInfomationManager', ['water.entity.videoInfomation','water.entity.monitorStation']);
	module.controller('VideoInfomationManagerController',function($wdp,$rootScope,$scope,$VideoInfomationService,$monitorStationService){
		/**
		 * 新建对话框
		 */
		$scope.createDialog;
		/**
		 * 编辑对话框
		 */
		$scope.editDialog;
		/**
		 * 新增数据
		 */
		$scope.datavideoInfomationCreate={};
		/**
		 * 编辑数据
		 */
		$scope.dataVideoInfomationEdit={};
		/**
		 * 查询条件
		 */
		$scope.queryObject={};
		/**
		 * 视频数据
		 */
		$scope.videoInfomationData={};
        /**
         * 初始化站点数据
         */
		$scope.stationSelectList=[];
		/**
		 *新建站点数据
		 */
		$scope.stationSelecter;
		/**
		 * 编辑站点数据
		 */
		$scope.stationSelecterEdit;
		/**
		 * 视频位置
		 */
		$scope.VideoPosition=[{k:"0",v:"站房内"},{k:"1",v:"采样点"}];
		/**
		 * 新建按钮点击
		 */
		$scope.onCreateClick=function(){
			$scope.datavideoInfomationCreate = {};
			$scope.createDialog.open();
		};
		/**
		 * 新建提交
		 */
		$scope.onSubmitCreateClick = function(data){
			var positonName="";
			if(data.VIDEO_POSITION=='0'){
				positonName="站房内";
			}
			if(data.VIDEO_POSITION=='1'){
				positonName="采样点";
			}
			data.NAME=data.STATION_NAME+positonName;
			$VideoInfomationService.createModel(data).then(function(){
				$scope._getVideoList();
				$.messager.alert("保存成功","保存成功",'info');
				$scope.createDialog.close();
			});
		};
		/**
		 * 新建取消按钮
		 */
		$scope.onSubmitCancleClick = function(){
				$scope.createDialog.close();
		};
		/**
		 * 编辑按钮点击事件
		 */
		$scope.onEditClick = function(data){
			$scope.dataVideoInfomationEdit = angular.copy(data);
			$scope.editDialog.open();
		}
		/**
		 * 提交编辑按钮点击事件
		 */
		$scope.onSubmitEditClick = function(data){
			var positonName="";
			if(data.VIDEO_POSITION=='0'){
				positonName="站房内";
			}
			if(data.VIDEO_POSITION=='1'){
				positonName="采样点";
			}
			data.NAME=data.STATION_NAME+positonName;
			$VideoInfomationService.updateModel(data).then(function(){
				$scope._getVideoList();
				$.messager.alert("保存成功","保存成功",'info');
				$scope.editDialog.close();
			});
		}
		/**
		 * 编辑取消事件
		 */
		$scope.onSubmitEditCancleClick = function(){
			$scope.editDialog.close();
	    };
		/**
		 * 删除
		 */
		$scope.onSubmitDeleteClick=function(data){
			$.messager.confirm("确认","确定要删除这条记录吗？",function(r){
				if(r){
					$VideoInfomationService.deleteModel(data.GUID).then(function(){
						$scope._getVideoList();
						$.messager.alert("删除成功","删除成功",'info');
					});			
				}
			});
		}
		/**
		 * 监控污水处理厂id变化
		 */
		if($wdp.viewValue.wwtpDetailParmWatch){
			$wdp.viewValue.wwtpDetailParmWatch();
		}
		$wdp.viewValue.wwtpDetailParmWatch = $rootScope.$watch(function(){return $wdp.viewValue.wwtpDetailParm;},function(){
			if(!$wdp.viewValue.wwtpDetailParm){
				return;
			}
			$scope.queryObject.WWTP_ID = $wdp.viewValue.wwtpDetailParm.WWTPID;
			$scope._getVideoList();
			$scope._getStationSelectList();
        },true);
		/**
		 * 获取视频数据
		 */
		$scope._getVideoList=function(){
			$VideoInfomationService.getList($scope.queryObject).then(function(d){
				if(d.data.length < 1){
					$scope.videoInfomationData = {};
					return;
				}
				$scope.videoInfomationData=d.data;
			});
		};
		/**
		 * 获取站点列表，编辑或者新增的时候需要选择
		 */
		$scope._getStationSelectList = function(){
			$monitorStationService.getDomainList({WWTP_ID:$scope.queryObject.WWTP_ID}).then(function(d){
				$scope.stationSelectList = d;
				$scope.stationSelecter.setData(d);
				$scope.stationSelecterEdit.setData(d);
			});
		};
	});
}(window, angular));